package shujia.day08;

/*
    把数组中的数据按照指定个格式拼接成一个字符串
    举例：int[] arr = {1,2,3};	输出结果：[1, 2, 3]
 */
public class StringTest3 {
    public static void main(String[] args) {
        int[] arr = {1,354,56,2,125,12};
//        arr = null;
        System.out.println(arrToStr(arr));
    }

    public static String arrToStr(int[] array) {
        if(array==null){
            return null;
        }

        String res = "[";
        for (int i = 0; i < array.length; i++) {
            if (i == array.length - 1) {
                res = res + array[i] + "]";
                break;
            }
            res = res + array[i] + ",";
        }
        return res;
    }
}
